<!DOCTYPE html>
<html>
<head>
    <title>成绩管理 - 学生成绩管理系统</title>
    <link rel="stylesheet" href="/static/css/home.css">
    <link rel="stylesheet" href="/static/css/list.css">
    <link rel="stylesheet" href="/static/css/scores.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
    <nav class="top-nav">
        <div class="nav-content">
            <a href="/" class="logo">学生成绩管理系统</a>
            <div class="user-info">
                <span class="welcome-text">欢迎，{{ request.user.username }}</span>
                <a href="{% url 'accounts:logout' %}" class="logout-btn">退出登录</a>
            </div>
        </div>
    </nav>

    <div class="container">
        <main class="main-content">
            <h1 class="page-title"><i class="fas fa-chart-line"></i> 成绩管理</h1>

            <!-- 统计信息 -->
            <div class="stats-container">
                <div class="stat-card">
                    <div class="stat-number">{{ scores|length }}</div>
                    <div class="stat-label">总记录数</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number">
                        {% with excellent_count=scores|length %}
                            {% for score in scores %}
                                {% if score.score >= 90 %}
                                    {% with excellent_count=excellent_count|add:1 %}
                                    {% endwith %}
                                {% endif %}
                            {% endfor %}
                            {{ excellent_count }}
                        {% endwith %}
                    </div>
                    <div class="stat-label">优秀成绩</div>
                </div>
                <div class="stat-card">
                    <div class="stat-number">
                        {% with avg_score=0 %}
                            {% for score in scores %}
                                {% with avg_score=avg_score|add:score.score %}
                                {% endwith %}
                            {% endfor %}
                            {% if scores %}
                                {{ avg_score|floatformat:1 }}
                            {% else %}
                                0
                            {% endif %}
                        {% endwith %}
                    </div>
                    <div class="stat-label">平均分</div>
                </div>
            </div>

            <div class="action-bar">
                <div class="search-box">
                    <input type="text" placeholder="🔍 搜索成绩（按学生姓名或科目）..." />
                </div>
                <a href="{% url 'scores:score_add' %}" class="btn-primary">
                    <i class="fas fa-plus"></i> 添加成绩
                </a>
            </div>

            <div class="card-grid">
                {% for score in scores %}
                <div class="data-card score-card">
                    <div class="card-header">
                        <div>
                            <h3 class="card-title">{{ score.student.name }}</h3>
                            <div class="card-subtitle">{{ score.subject }} - {{ score.term }}</div>
                        </div>
                        <div class="score-display 
                            {% if score.score >= 90 %}score-excellent
                            {% elif score.score >= 80 %}score-good
                            {% elif score.score >= 60 %}score-pass
                            {% else %}score-fail{% endif %}">
                            {{ score.score }}分
                        </div>
                    </div>
                    <div class="card-content">
                        <div class="info-row">
                            <span class="info-label">📚 班级：</span>
                            <span class="info-value">
                                {% if score.grade %}
                                    {{ score.grade.grade_name }}
                                {% else %}
                                    未设置
                                {% endif %}
                            </span>
                        </div>
                        <div class="info-row">
                            <span class="info-label">📅 记录日期：</span>
                            <span class="info-value">{{ score.date_recorded|date:"Y年m月d日" }}</span>
                        </div>
                        <div class="info-row">
                            <span class="info-label">🎯 等级：</span>
                            <span class="info-value">
                                {% if score.score >= 90 %}优秀
                                {% elif score.score >= 80 %}良好
                                {% elif score.score >= 70 %}中等
                                {% elif score.score >= 60 %}及格
                                {% else %}不及格{% endif %}
                            </span>
                        </div>
                    </div>
                    <div class="card-actions">
                        <a href="{% url 'scores:score_detail' score.pk %}" class="btn-action btn-view">
                            <i class="fas fa-eye"></i> 查看详情
                        </a>
                        <a href="{% url 'scores:score_edit' score.pk %}" class="btn-action btn-edit">
                            <i class="fas fa-edit"></i> 编辑成绩
                        </a>
                        <a href="{% url 'scores:score_delete' score.pk %}" class="btn-action btn-delete">
                            <i class="fas fa-trash"></i> 删除
                        </a>
                    </div>
                </div>
                {% empty %}
                <div class="no-data">
                    <i class="fas fa-chart-line" style="font-size: 3em; color: #ccc; margin-bottom: 20px;"></i>
                    <h3>暂无成绩记录</h3>
                    <p>点击上方"添加成绩"按钮来创建第一条成绩记录</p>
                </div>
                {% endfor %}
            </div>

            {% if scores.has_other_pages %}
            <div class="pagination">
                {% if scores.has_previous %}
                <a href="?page={{ scores.previous_page_number }}" class="btn-back">
                    <i class="fas fa-chevron-left"></i> 上一页
                </a>
                {% endif %}

                {% for i in scores.paginator.page_range %}
                <a href="?page={{ i }}" class="{% if scores.number == i %}active{% endif %}">{{ i }}</a>
                {% endfor %}

                {% if scores.has_next %}
                <a href="?page={{ scores.next_page_number }}" class="btn-primary">
                    下一页 <i class="fas fa-chevron-right"></i>
                </a>
                {% endif %}
            </div>
            {% endif %}

        </main>
    </div>
</body>
</html>